package edu.sctu.zhengsenwen.month201506.day20150628.game;

import java.awt.*;

/**
 * Created by user15 on 2015/6/28.
 */
public class GameFrame extends BaseFrame{

    Image image = GameUtil.getImage("images/95501.jpg");
    private int x = 200;
    private int y = 200;
    private double speed = 10;
    private double degree = Math.PI/3;        //[0,3.14*2]

    //在窗体里面画东西,这个是构造函数回调自动调用的，一定会被执行
    public void paint(Graphics g) {
        System.out.println("painting!!!");
        g.drawImage(image, x, y, null);  //通过每次画不同的位置实现动态效果

        if (speed > 0) {
            speed -= 0.1;
        }

        x += speed * Math.cos(degree);
        y += speed * Math.sin(degree);

        if (y > 600-40 || y < 30) {
            degree = -degree;
        }
        if (x > 600-40 || x < 0) {
            degree = Math.PI - degree;
        }
    }

    public static void main(String[] args) {
        GameFrame gFrame = new GameFrame();
        gFrame.launchFrame();
    }
}
